import java.util.*;

/**
 * @program: 2.19 Map
 * @description:
 * @author: 李鑫月
 * @create: 2022-02-19 11:45
 **/
public class TestDemo {
    //key是关键字  value是出现的次数
    public static Map<Integer, Integer> func1(int[] array) {
        Map<Integer, Integer> map = new HashMap<>();
        ArrayList<String> arrayList=new ArrayList<>();
        Scanner in = new Scanner(System.in);

//判断array中的元素 是否在map当中，如果不在就是1.在就是在原来的基础上+1
        for (int i = 0; i < array.length; i++) {
            if (map.get(array[i]) != null) {
                int val = map.get(array[i]);
                map.put(array[i], val + 1);
            } else {
                map.put(array[i], 1);
            }
        }
        return map;
    }

    public static Set<Integer> func2(int[] array) {
        Set<Integer> set = new HashSet<>();
        for (int x :
                array) {
            set.add(x);
        }
        return set;

    }

    public static int func3(int[] array) {
        Set<Integer> set = new HashSet<>();
        for (int x :
                array) {
            if (set.contains(x)) {
               return x;

            }

        }
        return -1;

    }

    public static void main(String[] args) {
        int[] array = new int[1_000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(1000);
        }

        Map<Integer, Integer> map = func1(array);
        System.out.println(map);
        System.out.println("***********************************************");
        Set<Integer> set = func2(array);
        System.out.println(set);
        int ret = func3(array);
        System.out.println(ret);
        String str="aaaaaaacc";


    }
}
